import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter/material.dart' as prefix0;
import 'package:village_android/component/Jd_Text.dart';
import 'package:village_android/component/jd_button.dart';
import 'package:village_android/pages/auth/register_second_page.dart';
import 'package:village_android/utils/common_utils.dart';
import 'package:village_android/utils/http_utlis.dart';

class RegisterFirstPage extends StatefulWidget {
  RegisterFirstPage({Key key}) : super(key: key);

  _RegisterFirstPageState createState() => _RegisterFirstPageState();
}

class _RegisterFirstPageState extends State<RegisterFirstPage> {
  String tel;
  String password;

  sendCode() async{
    RegExp reg=new RegExp(r"^1\d{10}$");
    if(reg.hasMatch(this.tel)){

      HttpUtils.post("/api/sendCode", data: {"phone": this.tel},
          success: (data) {
            CommonUtils.showToast(context, "验证码已发送");

            var page = RegisterSecondPage(arguments: {
              "tel":this.tel
            },);
            Navigator.push(context, new MaterialPageRoute(builder: (context) => page));

          }, error: (errorMsg) {
            print(errorMsg);
      });



    }else{
          CommonUtils.showToast(context, "手机号格式不对");

    }

  }
  @override
  Widget build(BuildContext context) {
    return  Scaffold(
      appBar: AppBar(
        title: Text('用户注册-验证手机'),
      ),
      body: Container(
        padding: EdgeInsets.all(20),
        child: ListView(
          children: <Widget>[
            SizedBox(height: 20),
            JdText(
              text: "请输入手机号",
              // password: true,
              onChanged: (value) {
                this.tel=value;
                // print(value);
              },
            ),
            SizedBox(height: 20),
            JdText(
              text: "请输入密码",
              // password: true,
              onChanged: (value) {
                this.tel=value;
                // print(value);
              },
            ),
            SizedBox(height: 20),
            JdButton(
                text: "下一步",
                color: Colors.red,
            )
          ],
        ),
      ),
    );
  }
}